package com.google.code.gwtmvpscaffold;

import static com.google.code.gwtmvpscaffold.SystemVariables.SEP;

import java.util.Map;

import com.google.common.collect.Maps;

/**
 * 
 * @author Ismet Ozalp
 * 
 */
public class Paths {

  /**
   * Filename,Filepath
   */
  public final Map<String, String> TEMPLATE_FILES_INPUT_PATH = Maps.newHashMap();
  public final Map<String, String> TEMPLATE_FILES_OUTPUT_PATH = Maps.newHashMap();

  public Paths(String packageName) {
    configureInputPaths();
    configureOutPutPaths(packageName);
  }

  private void configureInputPaths() {
    // .
    TEMPLATE_FILES_INPUT_PATH.put("pom.xml", "");
    TEMPLATE_FILES_INPUT_PATH.put("$DOT$project", "");
    TEMPLATE_FILES_INPUT_PATH.put("$DOT$classpath", "");

    // .settings
    TEMPLATE_FILES_INPUT_PATH.put("com.google.gdt.eclipse.core.prefs", "");
    TEMPLATE_FILES_INPUT_PATH.put("$DOT$jsdtscope", "");
    TEMPLATE_FILES_INPUT_PATH.put("com.google.gwt.eclipse.core.prefs", "");
    TEMPLATE_FILES_INPUT_PATH.put("org.eclipse.core.resources.prefs", "");
    TEMPLATE_FILES_INPUT_PATH.put("org.eclipse.jdt.core.prefs", "");
    TEMPLATE_FILES_INPUT_PATH.put("org.eclipse.m2e.core.prefs", "");
    TEMPLATE_FILES_INPUT_PATH.put("org.eclipse.wst.common.component", "");
    TEMPLATE_FILES_INPUT_PATH.put("org.eclipse.wst.common.project.facet.core.xml", "");

    // package.client
    TEMPLATE_FILES_INPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$.java", "");
    TEMPLATE_FILES_INPUT_PATH.put("ClientFactory.java", "");
    TEMPLATE_FILES_INPUT_PATH.put("ClientFactoryImpl.java", "");

    // package.client.widget
    TEMPLATE_FILES_INPUT_PATH.put("AppWidget.java", "");
    TEMPLATE_FILES_INPUT_PATH.put("AppWidget.ui.xml", "");

    // package.client.view
    TEMPLATE_FILES_INPUT_PATH.put("BasicView.java", "");

    // package.client.view.impl
    TEMPLATE_FILES_INPUT_PATH.put("AbstractBasicView.java", "");

    // package.client.place
    TEMPLATE_FILES_INPUT_PATH.put("BasicPlace.java", "");

    TEMPLATE_FILES_INPUT_PATH.put("AppPlaceHistoryMapper.java", "");

    // package.client.mvp
    TEMPLATE_FILES_INPUT_PATH.put("AbstractActivityMapper.java", "");

    // package.client.activity
    TEMPLATE_FILES_INPUT_PATH.put("AbstractBasicActivity.java", "");

    // package.server
    TEMPLATE_FILES_INPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$ServiceImpl.java", "");

    // package.shared
    TEMPLATE_FILES_INPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$Service.java", "");

    TEMPLATE_FILES_INPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$ServiceAsync.java", "");

    // package
    TEMPLATE_FILES_INPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$.gwt.xml", "");

    /**
     * others
     */

    // jsp
    TEMPLATE_FILES_INPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$.jsp", "");

    // web.xml
    TEMPLATE_FILES_INPUT_PATH.put("web.xml", "");

    // test class
    TEMPLATE_FILES_INPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$Test.java", "");

  }

  private void configureOutPutPaths(String packageName) {
    String[] split = packageName.split("\\.");
    String internalPath = "";
    for (String folder : split) {
      internalPath += SEP + folder;
    }

    // .
    TEMPLATE_FILES_OUTPUT_PATH.put("pom.xml", "");
    TEMPLATE_FILES_OUTPUT_PATH.put("$DOT$project", "");
    TEMPLATE_FILES_OUTPUT_PATH.put("$DOT$classpath", "");

    // .settings
    TEMPLATE_FILES_OUTPUT_PATH.put("com.google.gdt.eclipse.core.prefs", ".settings" + SEP);
    TEMPLATE_FILES_OUTPUT_PATH.put("$DOT$jsdtscope", ".settings" + SEP);
    TEMPLATE_FILES_OUTPUT_PATH.put("com.google.gwt.eclipse.core.prefs", ".settings" + SEP);
    TEMPLATE_FILES_OUTPUT_PATH.put("org.eclipse.core.resources.prefs", ".settings" + SEP);
    TEMPLATE_FILES_OUTPUT_PATH.put("org.eclipse.jdt.core.prefs", ".settings" + SEP);
    TEMPLATE_FILES_OUTPUT_PATH.put("org.eclipse.m2e.core.prefs", ".settings" + SEP);
    TEMPLATE_FILES_OUTPUT_PATH.put("org.eclipse.wst.common.component", ".settings" + SEP);
    TEMPLATE_FILES_OUTPUT_PATH.put("org.eclipse.wst.common.project.facet.core.xml", ".settings"
        + SEP);

    // package.client
    TEMPLATE_FILES_OUTPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$.java", "src" + SEP
        + "main" + SEP + "java" + internalPath + SEP + "client");
    TEMPLATE_FILES_OUTPUT_PATH.put("ClientFactory.java", "src" + SEP + "main" + SEP + "java"
        + internalPath + SEP + "client");
    TEMPLATE_FILES_OUTPUT_PATH.put("ClientFactoryImpl.java", "src" + SEP + "main" + SEP + "java"
        + internalPath + SEP + "client");

    // package.client.widget
    TEMPLATE_FILES_OUTPUT_PATH.put("AppWidget.java", "src" + SEP + "main" + SEP + "java"
        + internalPath + SEP + "client" + SEP + "widget");
    TEMPLATE_FILES_OUTPUT_PATH.put("AppWidget.ui.xml", "src" + SEP + "main" + SEP + "java"
        + internalPath + SEP + "client" + SEP + "widget");

    // package.client.view
    TEMPLATE_FILES_OUTPUT_PATH.put("BasicView.java", "src" + SEP + "main" + SEP + "java"
        + internalPath + SEP + "client" + SEP + "view");

    // package.client.view.impl
    TEMPLATE_FILES_OUTPUT_PATH.put("AbstractBasicView.java", "src" + SEP + "main" + SEP + "java"
        + internalPath + SEP + "client" + SEP + "view" + SEP + "impl");

    // package.client.place
    TEMPLATE_FILES_OUTPUT_PATH.put("BasicPlace.java", "src" + SEP + "main" + SEP + "java"
        + internalPath + SEP + "client" + SEP + "place");

    TEMPLATE_FILES_OUTPUT_PATH.put("AppPlaceHistoryMapper.java", "src" + SEP + "main" + SEP
        + "java" + internalPath + SEP + "client" + SEP + "place");

    // package.client.mvp
    TEMPLATE_FILES_OUTPUT_PATH.put("AbstractActivityMapper.java", "src" + SEP + "main" + SEP
        + "java" + internalPath + SEP + "client" + SEP + "mvp");

    // package.client.activity
    TEMPLATE_FILES_OUTPUT_PATH.put("AbstractBasicActivity.java", "src" + SEP + "main" + SEP
        + "java" + internalPath + SEP + "client" + SEP + "activity");

    // package.server
    TEMPLATE_FILES_OUTPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$ServiceImpl.java", "src"
        + SEP + "main" + SEP + "java" + internalPath + SEP + "server");

    // package.shared
    TEMPLATE_FILES_OUTPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$Service.java", "src" + SEP
        + "main" + SEP + "java" + internalPath + SEP + "shared");

    TEMPLATE_FILES_OUTPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$ServiceAsync.java", "src"
        + SEP + "main" + SEP + "java" + internalPath + SEP + "shared");

    // package
    TEMPLATE_FILES_OUTPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$.gwt.xml", "src" + SEP
        + "main" + SEP + "java" + internalPath);

    /**
     * others
     */

    // jsp
    TEMPLATE_FILES_OUTPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$.jsp", "src" + SEP + "main"
        + SEP + "webapp");

    // web.xml
    TEMPLATE_FILES_OUTPUT_PATH.put("web.xml", "src" + SEP + "main" + SEP + "webapp" + SEP
        + "WEB-INF");

    // test class
    TEMPLATE_FILES_OUTPUT_PATH.put("$PROJECT_NAME_CLASS_NAME_COMPATIBLE$Test.java", "src" + SEP
        + "test" + SEP + "java" + internalPath);
  }
}
